package com.edward.action;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.edward.model.PackingItem;
import com.edward.model.PackingList;
import com.edward.service.PackingListManager;
import com.opensymphony.xwork2.ActionSupport;

public class PrintPackingListAction extends ActionSupport{
	

	private static final long serialVersionUID = 7000562419610510545L;

	private List <PackingItem> list;
	
	private Map<String,Object> map;
	
	private PackingListManager packingListManager;
	
	private PackingList packingList;
	
	private PackingItem packingItem;
	

	public List<PackingItem> getList() {
		return list;
	}
	public void setList(List<PackingItem> list) {
		this.list = list;
	}
	public PackingList getPackingList() {
		return packingList;
	}
	public void setPackingList(PackingList packingList) {
		this.packingList = packingList;
	}
	public PackingItem getPackingItem() {
		return packingItem;
	}
	public void setPackingItem(PackingItem packingItem) {
		this.packingItem = packingItem;
	}
	public void setPackingListManager(PackingListManager packingListManager) {
		this.packingListManager = packingListManager;
	}
	public Map<String, Object> getMap() {
	        return map;
	    }
    public void setMap(Map<String, Object> map) {
	        this.map = map;
	    }





	public String execute() throws Exception {
		PackingList p = packingListManager.getPackingList(packingList.getId());
		list = p.getItems();
		map = testReflect(p);
		return SUCCESS;
	}
	

	
	 public static Map<String,Object> testReflect(Object obj) {      
		  Map<String,Object> hashMap = new HashMap<String,Object>();      
		  try {      
		   Class<? extends Object> c = obj.getClass();      
		   Method m[] = c.getDeclaredMethods();      
		   for (int i = 0; i < m.length; i++) {      
		    if (m[i].getName().indexOf("get")==0) {      
		     hashMap.put(m[i].getName(), m[i].invoke(obj, new Object[0]));      
		    }      
		   }      
		  } catch (Throwable e) {      
		   System.err.println(e);      
		  }      
		  return hashMap;      
		 }   

	
	
	
	

}
